package com.zp.game

import android.graphics.*
import game.engine.base.Sprite

class Progress @JvmOverloads constructor(
        var fgBitmap: Bitmap,
        bgBitmap: Bitmap,
        var percent: Float = 0f, // 进度 [0,1]
        x: Float = 0f,
        y: Float = 0f,
        degress: Float = 0f,
        ax: Float = 0.5f,
        ay: Float = 0.5f,
        sx: Float = 1.0f,
        sy: Float = 1.0f,
        zorder: Int = 0
) : Sprite(
        bitmap = bgBitmap,
        x = x,
        y = y,
        degress = degress,
        ax = ax,
        ay = ay,
        sx = sx,
        sy = sy,
        zorder = zorder
) {

    private val fgDstRect = RectF()

    val colorBg = Color.parseColor("#ebabab")
    val colorFg = Color.RED
    val paint = Paint(Paint.ANTI_ALIAS_FLAG)

    override fun onDraw(canvas: Canvas) {
//        super.onDraw(canvas)
//
//        // 绘制 fg
//        fgDstRect.set(dstRect.left,dstRect.top,dstRect.left + dstRect.width() * percent,dstRect.bottom)
//        canvas.drawBitmap(fgBitmap,null,fgDstRect,null)

        // 自己使用canvas绘制
        canvas.setMatrix(finalMatrix)
        updateDstRect()
        paint.color = colorBg
        canvas.drawRoundRect(dstRect.left, dstRect.top, dstRect.right, dstRect.bottom, 12f, 12f, paint)

        // 绘制 fg
        paint.color = colorFg
        fgDstRect.set(dstRect.left,dstRect.top,dstRect.left + dstRect.width() * percent,dstRect.bottom)
        canvas.drawRoundRect(fgDstRect.left, fgDstRect.top, fgDstRect.right, fgDstRect.bottom, 12f, 12f, paint)
    }
}